// ==UserScript==
// @name         vbox007's tools
// @namespace    https://gitee.com/vbox007/
// @version      1.0.0.1
// @description  vbox007's tools for zbcc
// @author       vbox007
// @icon         
// @match        *shangoue.meituan.com/*
// @match        https://zt.hiboos.com/vbox007
// @match        https://partner.dmall.com/
// @connect      *
// @grant        GM_xmlhttpRequest
// @grant        GM_getValue
// @grant        GM_setValue
// @grant        GM_deleteValue
// @require      https://cdn.bootcdn.net/ajax/libs/xlsx/0.16.9/xlsx.full.min.js
// @require      https://cdn.bootcdn.net/ajax/libs/qrcodejs/1.0.0/qrcode.js
// ==/UserScript==

(function () {
    'use strict';
    var $ = function (x) {
        return document.getElementById(x);
    };
    if (window.location.href.indexOf('https://zt.hiboos.com/vbox007') != -1) {
        (function () {
            document.head.innerHTML = '<title>vbox007\'s E-commerce tools</title>\n'
                + '<link rel="shortcut icon" type="image/ico" href="">\n'
                + '<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />\n'
                + '<style>\n'
                + '    body {margin: 0;}\n'
                + '    ul {list-style-type: none; margin: 0; padding: 0; overflow: hidden; background-color: #f3f3f3; position: fixed; top: 0; width: 100%;}\n'
                + '    li {float: left;}\n'
                + '    li a {display: block; color: #666; text-align: center; padding: 14px 16px; text-decoration: none;}\n'
                + '    li a:hover:not(.active) {background-color: #6ccf70;}\n'
                + '    li a.active {color: white; background-color: #4CAF50;}\n'
                + '    .emnt {border:1px solid #002244;font-size:12px;}\n'
                // + '    table {min-height:25px; line-height:16px; text-align:center; border-collapse:collapse; margin-bottom:0;}\n'
                + '    #fcenter {width:100%; overflow:auto; margin: 0 auto; margin-top:30px;}\n'
                + '    #dmsys {float:left;text-align:center;background:#f9cc9d;}\n'
                + '    #hbsys {float:left;text-align:center;background:#8bb5c0;}\n'
                + '    table {min-height:25px; line-height:16px; border-collapse:collapse; margin-bottom:0;}\n'
                + '    .divslm {margin: 0 auto; overflow:auto; text-align:center;}\n'
                + '    .thslm {white-space: nowrap; font-size:1px;}\n'
                + '    .tdslm {font-size: 1px;}\n'
                + '    .footer{position: absolute; bottom: 0; width: 100%; height: 52px; background-color: #ffc0cb;}\n'
                + '</style>';
        })();//修改页面head
        (function () {
            document.body.innerHTML = '<div>\n'
                + '    <ul>\n'
                + '        <li><a href="javascript:;">首页</a></li>\n'
                + '        <li><a href="javascript:;">订单监控</a></li>\n'
                + '        <li><a href="javascript:;">每日小结</a></li>\n'
                + '        <li><a href="javascript:;">日清日结</a></li>\n'
                + '        <li><a href="javascript:;">隐号查询</a></li>\n'
                + '        <li><a href="javascript:;">条码生成</a></li>\n'
                + '        <li><a href="javascript:;">high购增强</a></li>\n'
                + '        <li style="float:right"><a href="javascript:;">关于</a></li>\n'
                + '    </ul>\n'
                + '</div>\n'
                + '<div id="fcenter" style="">\n'//text-align:center;
                + '</div>\n'
                + '<div class="footer">底栏样式</div>\n';
        })();//修改页面body
    } else if (window.location.href.indexOf('shangoue.meituan.com') != -1) {
        (function () {
            console.log('***狗日的美团！！！***');
            var mtid = [0, 0];
            for (var i in localStorage) {
                //console.log(localStorage[i]);
                if (typeof (localStorage[i]) == 'string') {
                    if (localStorage[i].slice(2, 11) == 'accountId') {
                        mtid[0] = JSON.parse(localStorage[i]).accountId;
                    }
                    if (localStorage[i].slice(3, 10) == 'wmPoiId') {
                        mtid[1] = JSON.parse(localStorage[i])[0].wmPoiId;
                    }
                }
            }
            GM_setValue('mtid', mtid);
        })();
        return;
    } else if (window.location.href.indexOf('https://partner.dmall.com/') != -1) {
        var orderId = '';
        var truephone = '';
        var bind_displayphone = function (a_tag) {
            a_tag.onclick = (function (ev) {
                var js_ev = ev.target;
                if (js_ev.innerText == "隐藏") {
                    $("jcph").innerHTML = '<span class="tags blue">显示</span>';
                    $("consigneePhone").innerText = truephone.substr(0, 3) + '****' + truephone.substr(7);
                } else {
                    if (truephone == '' || orderId != $('orderId').innerText) {
                        orderId = $('orderId').innerText;
                        fetch("https://fulproduce-partner.dmall.com/produceOrderDetail/bindAXB?aNumber=13000000000&orderId=" + orderId + "&phoneType=1", {
                            "headers": {
                                "accept": "application/json, text/javascript, */*; q=0.01",
                                "accept-language": "zh-CN,zh;q=0.9",
                                "sec-ch-ua": "\"Google Chrome\";v=\"89\", \"Chromium\";v=\"89\", \";Not A Brand\";v=\"99\"",
                                "sec-ch-ua-mobile": "?0",
                                "sec-fetch-dest": "empty",
                                "sec-fetch-mode": "cors",
                                "sec-fetch-site": "same-site"
                            },
                            "referrer": "https://partner.dmall.com/",
                            "referrerPolicy": "strict-origin-when-cross-origin",
                            "body": null,
                            "method": "GET",
                            "mode": "cors",
                            "credentials": "include"
                        }).then(res => res.json()).then(pobj => {
                            truephone = pobj.data.bNumber;
                            $("consigneePhone").innerText = truephone;
                            $("jcph").innerHTML = '<span class="tags warning">隐藏</span>';
                        });
                    } else {
                        $("consigneePhone").innerText = truephone;
                        $("jcph").innerHTML = '<span class="tags warning">隐藏</span>';
                    }
                };
                return false;
            });
        }
        var waitlb = function () {
            if ($('orderId') == null) {
                return setTimeout(waitlb, 128);
            }
            if ($('orderId').innerText == orderId) {
                return setTimeout(waitlb, 128);
            }
            orderId = $('orderId').innerText;
            $("consigneePhoneShowDiv").innerHTML = '<a id="jcph" href="#"><span class="tags blue">显示</span></a>'
            bind_displayphone($('jcph'));
            $("consigneePhoneShowDiv").style.display = '';
            setTimeout(waitlb, 128);
        };
        if (window.location.href.indexOf('#index/produceCenter') != -1) {
            setTimeout(waitlb, 128);
        }
    } else {
        return;
    }
    var homediv = function () {
        var uphis = [
            [
                'V1.0.0.0(2021/05/31)',
                '此工具页正式立项'
            ], [
                'V1.0.0.1(2021/06/12)',
                '增加了网站底栏界面（未写入功能）',
                '尝试把真实号码功能合并过来',
                '修改了脚本和网站的图标'
            ]
        ]
        $('fcenter').innerHTML = '<h1>更新内容：</h1>\n'
        for (var i = 0; i < uphis.length; i++) {
            $('fcenter').innerHTML += '<p>\n'
            $('fcenter').innerHTML += '    ' + uphis[i][0] + ':<br>\n'
            if (uphis[i].length == 2) {
                $('fcenter').innerHTML += '    &nbsp;&nbsp;&nbsp;&nbsp;' + uphis[i][1] + '<br/>\n'
            } else if (uphis[i].length > 2) {
                for (var j = 1; j < uphis[i].length; j++) {
                    $('fcenter').innerHTML += '    &nbsp;&nbsp;&nbsp;&nbsp;' + j + '.' + uphis[i][j] + '<br/>\n'
                }
            }
            $('fcenter').innerHTML += '</p>\n';
        }
    }
    var monitordiv = function () {
    }
    var nava = document.getElementsByTagName('a');
    for (var i = 0; i < 8; i++) {
        nava[i].onclick = (function (ev) {
            for (var i = 0; i < 8; i++) {
                if (nava[i] != ev.target) {
                    nava[i].className = '';
                } else {
                    switch (i) {
                        case 0:
                            homediv();
                            break;
                        case 1:
                            $('fcenter').innerHTML = '<h1>订单监控开发中……</h1>\n';
                            break;
                        case 2:
                            $('fcenter').innerHTML = '<h1>每日小结开发中……</h1>\n';
                            break;
                        case 3:
                            $('fcenter').innerHTML = '<h1>日清日结开发中……</h1>\n';
                            break;
                        case 4:
                            $('fcenter').innerHTML = '<h1>隐号查询开发中……</h1>\n';
                            break;
                        case 5:
                            $('fcenter').innerHTML = '<h1>条码生成开发中……</h1>\n';
                            break;
                        case 6:
                            $('fcenter').innerHTML = '<h1>high购增强开发中……</h1>\n';
                            break;
                        case 7:
                            $('fcenter').innerHTML = '<h1>这里是关于页面</h1>\n';
                            break;
                        default:
                    }
                    ev.target.className = 'active';
                }
            }
            return false;
        });
    }
    nava[0].click();
    var getstrtime = function (difft, c_type, c_one) {
        var nowdate = new Date();
        if (difft) {
            nowdate.setTime(nowdate.getTime() + difft);
        }
        var nowmon = nowdate.getMonth() + 1;
        var strDate = nowdate.getDate();
        if (nowmon >= 1 && nowmon <= 9) {
            nowmon = "0" + nowmon;
        }
        if (strDate >= 0 && strDate <= 9) {
            strDate = "0" + strDate;
        }
        var cdate;
        if (c_type == 1) {
            if (c_one) {
                cdate = '' + nowdate.getFullYear() + nowmon + "01";
            } else {
                cdate = '' + nowdate.getFullYear() + nowmon + strDate;
            }
        } else if (c_type == 2) {
            cdate = nowdate.getFullYear() + '年' + nowmon + '月' + strDate + '日';
        } else {
            cdate = nowdate.getFullYear() + '-' + nowmon + '-' + strDate;
        }
        return cdate;
    }//获取今天的日期文本
    var get_dmall_id = function () {
        // loadnum[0] = 2;
        GM_xmlhttpRequest({
            method: "post",
            url: "https://waybillsmartallot-partner.dmall.com/api/getStoreList",
            data: null,
            headers: {
                "accept": "application/json, text/javascript, */*; q=0.01",
                "accept-language": "zh-CN,zh;q=0.9",
                "sec-fetch-dest": "empty",
                "sec-fetch-mode": "cors",
                "sec-fetch-site": "same-site"
            },
            onload: function (res) {
                try {
                    var pobj = JSON.parse(res.responseText);
                    for (var i = 0; i < pobj.data.length; i++) {
                        $('storeid').options[i] = new Option(pobj.data[i].storeName);
                        $('storeid').options[i].value = pobj.data[i].storeId;
                    }
                    // dmsid = $('storeid').options[0].value;
                    $('storeid').options[0].selected = true;
                    $('storeid').style.display = 'block';
                    // myec &= ~3;
                    // loadnum[0] = 3;
                } catch (error) {
                    // myec |= 1;
                    // loadnum[0] = 3;
                    console.log('*');
                    console.log(error.message);
                    console.log('*');
                }
            },
            onerror: function (err) {
                // myec |= 2;
                // loadnum[0] = 3;
                console.log('*');
                console.log(err);
                console.log('*');
            }
        });
    };//取多点来客系统中的门店编号
    // Your code here...
})();